#!/bin/bash
# 更新 net/gdface/bean/openbeans 下所有对java.beans包的引用为com.googlecode.openbeans
# Default case for Linux sed, just use "-i"
sedi=(-i)
case "$(uname)" in
  # For macOS, use two parameters
  Darwin*) sedi=(-i "")
esac

rm -fr src/main/java/net/gdface/bean/openbeans/* || exit
cp -r src/main/java/net/gdface/bean/jdk/*  src/main/java/net/gdface/bean/openbeans || exit

find src/main/java/net/gdface/bean/openbeans -name "*.java" -type f | while read fname;
do 
  echo refact $fname
  # 替换包名
  sed "${sedi[@]}" -r "s/import[[:space:]]+java\.beans/import com\.googlecode\.openbeans/g" "$fname" || exit
  sed "${sedi[@]}" -r "s/package[[:space:]]+net\.gdface\.bean\.jdk/package net\.gdface\.bean\.openbeans/g" "$fname" || exit
  sed "${sedi[@]}" -r "s/import[[:space:]]+net\.gdface\.bean\.jdk/import net\.gdface\.bean\.openbeans/g" "$fname" || exit
done || exit